package com.pxst.dashboard.service.Info;

import com.pxst.dashboard.mapper.InfoMapper;
import com.pxst.dashboard.resp.CountAndAmount;
import com.pxst.dashboard.resp.InfoResp;
import com.pxst.dashboard.service.InfoService;
import com.pxst.resp.ApiResp;
import com.pxst.sys.service.SysCurrencyConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.pxst.fo.sys.constants.FoConstants.CONFIRM_ACCNAME_ADMIN;
import static com.pxst.fo.sys.constants.FoConstants.CONFIRM_ACCNAME_MERCHANT;

/**
 * @author rj
 * @create 2023-11-02-15:52
 */
@Service
public class InfoServiceImpl implements InfoService {

    @Autowired
    private InfoMapper infoMapper;

    @Autowired
    private SysCurrencyConfigService currencyConfigService;

    @Override
    public ApiResp<InfoResp> getInfo() {

        // 获取所有的币种
        List<String> currencyList = currencyConfigService.currencyList();
        Map<String, CountAndAmount> processingFo = new HashMap<>();
        Map<String, CountAndAmount> processingFx = new HashMap<>();
        Map<String, CountAndAmount> merConfirmFo = new HashMap<>();
        Map<String, CountAndAmount> confirmableFo = new HashMap<>();
        Map<String, CountAndAmount> approvalExternal = new HashMap<>();
        for (String currency : currencyList) {
            // 获取玩家提现等待中数量和金额
            processingFo.put(currency, infoMapper.sumProcessingTransactions("sys_fo_order_main", currency));
            // 获取商户结算等待中数量和金额
            processingFx.put(currency, infoMapper.sumProcessingTransactions("sys_fx_order", currency));
            // 获取玩家提现待审核数量和金额
            confirmableFo.put(currency, infoMapper.sumConfirmableTransactions(currency, CONFIRM_ACCNAME_ADMIN));
            // 获取等待商户确认的结算数量和金额
            merConfirmFo.put(currency, infoMapper.sumConfirmableTransactions(currency, CONFIRM_ACCNAME_MERCHANT));
            // 获取外传待审核数量和金额
            approvalExternal.put(currency, infoMapper.sumApprovalExternal(currency));
        }
        // 封装返回值
        InfoResp infoResp = new InfoResp();
        infoResp.setProcessingFo(processingFo);
        infoResp.setProcessingFx(processingFx);
        infoResp.setProcessingFx(merConfirmFo);
        infoResp.setProcessingFx(confirmableFo);
        infoResp.setProcessingFx(approvalExternal);
        return ApiResp.sucess(infoResp);
    }

}
